import Vue from 'vue'
const manaccount = {
  // 获取账户列表
  accountList: function accountList(ip, postdata) {
    var ipPath = ip + '?pageNo=' + postdata.pageNo + '&pageSize=' + postdata.pageSize
    return Vue.http.get(ipPath, postdata).then(response => {
      if (response.status === 200) {
        return Promise.resolve(response.body)
      } else {
        return Promise.reject(response.data.message)
      }
    })
  },
  // 修改账户
  accountUpdate: function accountUpdate(ip, postdata) {
    var ipPath = ip + '/' + postdata.id + '?enable=' + postdata.enable
    return Vue.http.get(ipPath, postdata).then(response => {
      if (response.status === 200) {
        return Promise.resolve(response.body)
      } else {
        return Promise.reject(response.data.message)
      }
    })
  },
  // 删除账户
  accountDel: function accountDel(ip, postdata) {
    var ipPath = ip + '/' + postdata.id
    return Vue.http.get(ipPath, postdata).then(response => {
      if (response.status === 200) {
        return Promise.resolve(response.body)
      } else {
        return Promise.reject(response.data.message)
      }
    })
  },
  // 账户添加关联-添加角色Id
  ARaddRole: function ARaddRole(ip, postdata) {
    var ipPath = ip + '?accountId=' + postdata.accountId + '&roleId=' + postdata.roleId
    return Vue.http.post(ip, postdata).then(response => {
      if (response.status === 200) {
        return Promise.resolve(response.body)
      } else {
        return Promise.reject(response.data.message)
      }
    })
  },
  // 账户添加关联-删除所有角色
  ARdelRoleAll: function ARdelRoleAll(ip, postdata) {
    var ipPath = ip + '/' + postdata.accountId
    return Vue.http.get(ipPath, {}).then(response => {
      if (response.status === 200) {
        return Promise.resolve(response.body)
      } else {
        return Promise.reject(response.data.message)
      }
    })
  },
  // 账户添加关联-删除指定角色
  ARdelRoleId: function ARdelRoleId(ip, postdata) {
    var ipPath = ip + '/' + postdata.accountId + '/' + postdata.roleId
    return Vue.http.get(ipPath, {}).then(response => {
      if (response.status === 200) {
        return Promise.resolve(response.body)
      } else {
        return Promise.reject(response.data.message)
      }
    })
  },
  // 账户添加关联-获取账户下角色id
  ARfindRoleId: function ARfindRoleId(ip, postdata) {
    var ipPath = ip + '/' + postdata.accountId
    return Vue.http.get(ipPath, {}).then(response => {
      if (response.status === 200) {
        return Promise.resolve(response.body)
      } else {
        return Promise.reject(response.data.message)
      }
    })
  },
  // 账户添加关联-获取账户下角色
  ARfindAccountRole: function ARfindAccountRole(ip, postdata) {
    var ipPath = ip + '/' + postdata.accountId
    return Vue.http.get(ipPath, {}).then(response => {
      if (response.status === 200) {
        return Promise.resolve(response.body)
      } else {
        return Promise.reject(response.data.message)
      }
    })
  },
  // 角色-添加角色
  addRole: function addRole(ip, postdata) {
    var ipPath = ip + '?name=' + postdata.name + '?code=' + postdata.code
    return Vue.http.post(ip, postdata).then(response => {
      if (response.status === 200) {
        return Promise.resolve(response.body)
      } else {
        return Promise.reject(response.data.message)
      }
    })
  },
  // 角色-删除角色
  delRole: function delRole(ip, postdata) {
    var ipPath = ip + '/' + postdata.id
    return Vue.http.get(ipPath, postdata).then(response => {
      if (response.status === 200) {
        return Promise.resolve(response.body)
      } else {
        return Promise.reject(response.data.message)
      }
    })
  },
  // 角色-获取角色列表分页
  getRoleAllPage: function findRole(ip, postdata) {
    var ipPath = ip + '?pageNo=' + postdata.pageNo + '&pageSize=' + postdata.pageSize
    console.log(ipPath)
    return Vue.http.get(ipPath, postdata).then(response => {
      if (response.status === 200) {
        return Promise.resolve(response.body)
      } else {
        return Promise.reject(response.data.message)
      }
    })
  },
  // 角色-获取角色列表全部
  findRole: function findRole(ip) {
    var ipPath = ip
    console.log(ipPath)
    return Vue.http.get(ipPath).then(response => {
      if (response.status === 200) {
        return Promise.resolve(response.body)
      } else {
        return Promise.reject(response.data.message)
      }
    })
  },
  // 角色-查询指定角色
  findRoleId: function findRoleId(ip, postdata) {
    var ipPath = ip + '/' + postdata.id
    return Vue.http.get(ipPath, postdata).then(response => {
      if (response.status === 200) {
        return Promise.resolve(response.body)
      } else {
        return Promise.reject(response.data.message)
      }
    })
  },
  // 角色-修改角色
  updateRole: function updateRole(ip, postdata) {
    var ipPath = ip + '?createDate=' + postdata.createDate + '&updateDate=' + postdata.updateDate + '&logicDelete=' + postdata.logicDelete + '&id=' + postdata.id + '&name=' + postdata.name + '&code=' + postdata.code
    return Vue.http.post(ip, postdata).then(response => {
      if (response.status === 200) {
        return Promise.resolve(response.body)
      } else {
        return Promise.reject(response.data.message)
      }
    })
  },
  // 资源-获取资源列表
  findResource: function findResource(ip, postdata) {
    var ipPath = ip + '?pageNo=' + postdata.pageNo + '&pageSize=' + postdata.pageSize
    console.log(ipPath)
    return Vue.http.get(ipPath, postdata).then(response => {
      if (response.status === 200) {
        return Promise.resolve(response.body)
      } else {
        return Promise.reject(response.data.message)
      }
    })
  },
  // 资源-查询资源树
  findResourceTherr: function findResourceTherr(ip, postdata) {
    return Vue.http.get(ip, {}).then(response => {
      if (response.status === 200) {
        return Promise.resolve(response.body)
      } else {
        return Promise.reject(response.data.message)
      }
    })
  },
  // 资源-修改资源
  updateResource: function updateResource(ip, postdata) {
    return Vue.http.post(ip, postdata).then(response => {
      if (response.status === 200) {
        return Promise.resolve(response.body)
      } else {
        return Promise.reject(response.data.message)
      }
    })
  },
  // 资源-查看单个资源
  findOneResource: function findOneResource(ip, postdata) {
    var ipPath = ip + '/' + postdata.id
    return Vue.http.get(ipPath, {}).then(response => {
      if (response.status === 200) {
        return Promise.resolve(response.body)
      } else {
        return Promise.reject(response.data.message)
      }
    })
  },
  // 资源-删除资源
  delResource: function delResource(ip, postdata) {
    var ipPath = ip + '/' + postdata.id
    return Vue.http.get(ipPath, {}).then(response => {
      if (response.status === 200) {
        return Promise.resolve(response.body)
      } else {
        return Promise.reject(response.data.message)
      }
    })
  },
  // 资源-添加资源
  addResource: function addResource(ip, postdata) {
    return Vue.http.post(ip, postdata).then(response => {
      if (response.status === 200) {
        return Promise.resolve(response.body)
      } else {
        return Promise.reject(response.data.message)
      }
    })
  },
  // 角色资源-查询角色资源树
  roleResourceFindTher: function roleResourceFindTher(ip, postdata) {
    var ipStr = ip + '/' + postdata.roleId
    return Vue.http.get(ipStr, {}).then(response => {
      if (response.status === 200) {
        return Promise.resolve(response.body)
      } else {
        return Promise.reject(response.data.message)
      }
    })
  },
  // 角色资源-添加角色资源
  roleResourceAddTher: function roleResourceAddTher(ip, postdata) {
    return Vue.http.post(ip, postdata).then(response => {
      if (response.status === 200) {
        return Promise.resolve(response.body)
      } else {
        return Promise.reject(response.data.message)
      }
    })
  },
  // 角色资源-删除所有资源
  roleResourceDelAllTher: function roleResourceDelAllTher(ip, postdata) {
    var ipStr = ip + '/' + postdata.roleId
    return Vue.http.get(ipStr, {}).then(response => {
      if (response.status === 200) {
        return Promise.resolve(response.body)
      } else {
        return Promise.reject(response.data.message)
      }
    })
  },
  // 角色资源-删除指定角色资源
  roleResourceDelOneTher: function roleResourceDelOneTher(ip, postdata) {
    var ipStr = ip + '/' + postdata.roleId + '/' + postdata.resourcesId
    return Vue.http.get(ipStr, {}).then(response => {
      if (response.status === 200) {
        return Promise.resolve(response.body)
      } else {
        return Promise.reject(response.data.message)
      }
    })
  },
  // 角色资源-查询路径
  roleResourceFindpath: function roleResourceFindpath(ip, postdata) {
    var ipStr = ip + '/' + postdata.roleId
    return Vue.http.get(ipStr, {}).then(response => {
      if (response.status === 200) {
        return Promise.resolve(response.body)
      } else {
        return Promise.reject(response.data.message)
      }
    })
  }


}

export default manaccount
